from django.db import models

# Create your models here.

class BookInfo(models.Model):
    # 属性名=属性类型（选项）
    # 不要使用关键字和连续的下划线
    # 类型和mysql类似的

    # CharField必须设置max_length
    # unique是否唯一
    name=models.CharField(max_length=10,unique=True)
    # 是否为空
    pub_data=models.DateField(null=True)
    read_count=models.IntegerField(default=0)
    comment_count=models.IntegerField(default=0)
    is_delete=models.BooleanField(default=False)
    def __str__(self):
        return self.name

class PeopleInfo(models.Model):
    # 性别的写法，枚举字典
    GENDER_CHOICES=(
        (0,'male'),
        (1,'female')
    )
    name = models.CharField(max_length=20,verbose_name='名称')
    gender = models.SmallIntegerField(choices=GENDER_CHOICES,default=0,verbose_name='性别')
    description = models.CharField(max_length=200,null=True,verbose_name='描述')
    book = models.ForeignKey(BookInfo,on_delete=models.CASCADE,verbose_name='书名')
    is_delete = models.BooleanField(default=True,verbose_name='逻辑删除')

    class Meta:
        db_table = 'peopleinfo'
        verbose_name = '人物信息'

    def __str__(self):
        return  self.name